package com.hoas.quickstart.threads.chapter06.chapter06_4_1;

import java.io.*;

public class SaveAndRead {

    public static void main(String[] args) {
        try {
            MyObject myObject = MyObject.getInstance();
            FileOutputStream  fosRef = new FileOutputStream(new File("e:\\myObjectFile.txt"));
            ObjectOutputStream oosRef = new ObjectOutputStream( fosRef );
            oosRef.writeObject( myObject);

            oosRef.close();
            fosRef.close();
            System.out.println(myObject.hashCode());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            FileInputStream fisRef = new FileInputStream( new File("e:\\myObjectFile.txt"));
            ObjectInputStream iosRef = new ObjectInputStream( fisRef );
            MyObject myObject = (MyObject) iosRef.readObject();
            iosRef.close();
            fisRef.close();
            System.out.println(myObject.hashCode());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

}
